<template>
  <el-select v-model="selectedProject" placeholder="请选择项目"  @change="handleChange" style="width:250px;">
      <el-option
        v-for="item in projectsList"
        :key="item.value"
        :label="item.label"
        :value="item.value">
      </el-option>
    </el-select>
</template>

<script>
import commonApi from '@/api/kylin/common'

export default {
  props: {
    value: { required: true }
  },
  data() {
    return {
      selectedProject: '',
      projectsList: []
    }
  },
  watch: {
    value: {
      handler(val) {
        this.selectedProject = val
      }
    }
  },
  mounted() {
    var _this = this
    commonApi.projects().then(resp => { _this.projectsList = resp.data })
  },
  methods: {
    handleChange() {
      this.$emit('input', this.selectedProject)
      this.$emit('change', this.selectedProject)
    }
  }
}
</script>
